# coding: utf-8

from wtforms import DecimalField, StringField, DateField
from wtforms.validators import DataRequired, Length, NumberRange, ValidationError, AnyOf

from server.utils.forms import BaseForm


class AccTradeForm(BaseForm):
    acc_id = StringField(validators=[DataRequired(), Length(min=6, max=6, message="转入账号格式错误")])
    type_ = StringField(validators=[DataRequired(), AnyOf(values=["转入", "转出", "盈利", "亏损"])])
    amount = DecimalField(validators=[DataRequired(), NumberRange(min=0, message="金额不能为负")])
    post_date = DateField(validators=[DataRequired()])

    def validate_acc_in(self, value):
        if self.acc_out.data == value.data:
            raise ValidationError(message="转入、转出账号相同")
